package com.ycdx.zwzc.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.ycdx.zwzc.impl.UserImpl;
import com.ycdx.zwzc.pojo.User;
import com.ycdx.zwzc.utils.MD5Util;

public class LoginAction extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = -6201098577957165589L;
	
	private User user;
	private User tempUser = new User();
	
	private Map<String,Object> session;
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String login(){
		//根据传来值进行验证
		boolean flag = UserImpl.isLeagal(user.getUsername(), MD5Util.MD5(user.getPassword()));
		if(flag){
			//用户合法
			tempUser = UserImpl.getUser(user.getUsername(), MD5Util.MD5(user.getPassword()));
			session.put("user",tempUser);
			return "loginSuccess";
		}else{
			this.addActionMessage("帐号或密码错误，请检查！");
			return "loginError";			
		}
		
	}

	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}
}
